<?php
class Book extends AppModel {
	var $name = 'Book';
	var $displayField = 'id';
	var $validate = array(
		'producer_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'publisher' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Producer' => array(
			'className' => 'Producer',
			'foreignKey' => 'producer_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	var $hasOne = array(
		'Product' => array(
			'className' => 'Product',
			'foreignKey' => 'id',
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'dependent' => true
		)
	);
	/*
	function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) {
		$recursive = -1;
		$group = $fields = array('id', 'name', 'image', 'producer_id', 'publisher','genre', 'score','sold_count', 'stock_count', 'description', 'price');
		return $this->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive', 'group'));
	}
	
	var $paginate = array(
		'Book' => array('limit' => 20,
			'order' => array('id' => 'desc'),
			'group' => array('id', 'name', 'image', 'producer_id', 'publisher','genre', 'score','sold_count', 'stock_count', 'description', 'price')
		)
	);
	
	function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
		$sql = "SELECT p.id,p.name,p.image,p.genre,p.score,p.stock_count,p.sold_count,
				 p.price,b.producer_id,b.publisher from books as b, products as p where b.id=p.id";
		$this->recursive = $recursive;
		$results = $this->query($sql);
		return count($results);
	}
	*/
}
